<?php
include("include/cfg_login.php");
include("include/functions.php");
include("../includes/limba/ro/limba.php");
	$id_eveniment = $_GET['id'];
	$resMain = mysql_query("select * from evenimente where id_cutremur = '$id_eveniment'  ");
	$rowEveniment = mysql_fetch_array($resMain);
?>

<html>
	<head>
		<link href="css/style.css" rel="stylesheet">
		<link href="../css/start/jquery-ui-1.10.4.custom.css" rel="stylesheet">
	</head>
	<body>
		<div id="adminMenu">
			<?php include("include/menu.php"); ?>
		</div>
		<div id="content">
			<div id="contentWrap">
				
				<h2> <b>Cutremur de : <font style="font-size:22px;"><?php echo $rowEveniment['mag']; ?></font> in <?php echo $rowEveniment['regiune']; ?> </b> la <?php echo $rowEveniment['data_eveniment']; ?></h2>
				<div id="legenda">
				<b>Legenda:</b><br />
				<?php for($i=1;$i<13;$i++):?>
				<div  title="<?php echo $_['raspuns-'.$i]; ?>" class="legendaCulori color<?php echo $i; ?>"><?php echo $i; ?></div>
				<?php endfor; ?>
				<div style="clear:both"></div>
				</div>
				<div id="map"></div>
				<div id="dialogEveniment" title="Comentariu eveniment"></div>
				<h2> Comentarii </h2>
				<div id="comantarii">
					
					<div id="lista_comentarii"></div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 
	<script src="../js/jquery-1.10.2.js"></script>
	<script src="../js/jquery-ui-1.10.4.custom.js"></script>
	<script>
		var map;
		var feedback = {};
		<?php
			$id_eveniment = $_GET['id'];
			$res = mysql_query("select * from feedback where id_eveniment = '$id_eveniment'  ");
			while($row = mysql_fetch_array($res)):
				$coordonate = $row['coordonate'];
				if($coordonate == ""){
					$lat  = "44.4325";
					$lng =  "26.1038889";
				}else{
					$coordonate = str_replace("(","",$coordonate);
					$coordonate = str_replace(")","",$coordonate);
					$coordonate = explode(",",$coordonate);
					$lat = $coordonate[0];
					$lat = number_format($lat,6);
					$lng = $coordonate[1];
					$lng = number_format($lng,6);
				}
				
		?>
			feedback['<?php echo $row['id_raspuns']; ?>'] = {
				center: new google.maps.LatLng(<?php echo $lat ?>, <?php echo $lng; ?>),
				culoare: "<?php culoare($row['intensitate']); ?>",
				mesaj: "<?php culoare($row['intensitate']); ?>",
				imagine: '<?php echo "img/".$row['intensitate'].".png"; ?>',
				comentariu: '<?php echo str_replace(PHP_EOL, '', $row['comentariu']); ?>'
			};
		<?php endwhile; ?>
		
		var feedbackCircle;
		
		function initialize() {
		  var mapOptions = {
			zoom: 7,
			center: new google.maps.LatLng(46.00, 25.00),
			 mapTypeId: google.maps.MapTypeId.HYBRID ,
			 scaleControl: false,
			 zoomControl: true,
			 panControl: false,
			 streetViewControl:false,
			 mapTypeControl:false
		  };
		 map = new google.maps.Map(document.getElementById('map'),
		 mapOptions);
		 
		 var feedbackCircle = new Array()
		  for (var feedbackUser in feedback) {
			var feedbackOptions = {
				  position: feedback[feedbackUser].center,
				  map: map,
				  opacity: 0.8,
				  icon: feedback[feedbackUser].imagine,
				  comment: feedback[feedbackUser].comentariu
				};
				feedbackCircle[feedbackUser]   = new google.maps.Marker(feedbackOptions);
		  }
		 
		 for (var i=1;i<feedbackCircle.length;i++){
				google.maps.event.addListener(feedbackCircle[i], 'click', function(innerNr) {
						return function() {
						//	alert(feedbackCircle[innerKey].comment);
							//new google.maps.InfoWindow({content: feedbackCircle[innerNr].comment}).open(map,feedbackCircle[innerNr]);
							$("#dialogEveniment").dialog().html(feedbackCircle[innerNr].comment);
						}
				}(i));
			}
		
		}
		google.maps.event.addDomListener(window, 'load', initialize);
		

		function coment(){
			idEveniment = <?php echo $id_eveniment; ?>;
			$.ajax({
				dataType:"JSON",
				url:"ajax.php",
				type:"post",
				data:{"comentarii":"da","idEveniment":idEveniment}
			}).done(function(data){
				$.each(data, function(nr,comArr){
					if($("#n"+comArr.id_raspuns).length == 0 ){
						if($(".coment").length == 0){
							$("#lista_comentarii").append('<div class="coment" id="n'+comArr.id_raspuns+'"><div class="adresa">'+comArr.adresa+'</div><div class="comm">'+comArr.comentariu+'</div><div class="dataComentariu">'+comArr.data_raspuns+'</div></div>');
						}else{
							$(".coment:first").before('<div class="coment"  id="n'+comArr.id_raspuns+'"><div class="adresa">'+comArr.adresa+'</div><div class="comm">'+comArr.comentariu+'</div><div class="dataComentariu">'+comArr.data_raspuns+'</div></div>');
						}
					}
				})
			})
		}
	
			

		$('document').ready(function(){
			coment()
			setInterval("coment()",1000);
		})
	</script>
</html>